#!/usr/bin/env python
# coding=utf-8

import json
import requests

CHBTC_ticker = "http://api.chbtc.com/data/v1/ticker?currency="
YUNBI_ticker = "https://yunbi.com//api/v2/tickers/"
HUOBI_ticker = ""
OKCOIN_ticker = "https://www.okcoin.cn/api/v1/ticker.do?symbol="
COINBASE_ticker = ""
BTCE_ticker = "https://btc-e.com/api/3/ticker/"
POLONIEX_ticker = "https://poloniex.com/public?command=returnTicker"

"""
用人民币在中国的交易所买btc，将买到的btc转到国外交易所的btc账户中,
减去比特币转账的手续费0.0001btc。从国外交易所利用btc购买eth，将得到
的eth转入到国内交易所的eth账户中，再卖出，得到的最大利润
"""

def get_max_profit_btc_eth(money) :

    btc2cny = {}
    eth2btc = {}
    eth2cny = {}

    CHBTC_btc_cny_ticker_r = requests.get(CHBTC_ticker+"btc_cny")
    CHBTC_btc_cny = float(json.loads(CHBTC_btc_cny_ticker_r.text)["ticker"]["last"])
    CHBTC_eth_cny_ticker_r = requests.get(CHBTC_ticker+"eth_cny")
    CHBTC_eth_cny = float(json.loads(CHBTC_eth_cny_ticker_r.text)["ticker"]["last"])

    YUNBI_btc_cny_ticker_r = requests.get(YUNBI_ticker+"btccny.json")
    YUNBI_btc_cny = float(json.loads(YUNBI_btc_cny_ticker_r.text)["ticker"]["last"])
    YUNBI_eth_cny_ticker_r = requests.get(YUNBI_ticker+"ethcny.json")
    YUNBI_eth_cny = float(json.loads(YUNBI_eth_cny_ticker_r.text)["ticker"]["last"])

    OKCOIN_btc_cny_ticker_r = requests.get(OKCOIN_ticker+"btc_cny")
    OKCOIN_btc_cny = float(json.loads(OKCOIN_btc_cny_ticker_r.text)["ticker"]["last"])
    #OKCOIN_eth_cny_ticker_r = requests.get(OKCOIN_ticker+"eth_cny")
    #OKCOIN_eth_cny = float(json.loads(OKCOIN_eth_cny_ticker_r.text)["ticker"]["last"])

    BTCE_eth_btc_ticker_r = requests.get(BTCE_ticker+"eth_btc")
    BTCE_eth_btc = float(json.loads(BTCE_eth_btc_ticker_r.text)["eth_btc"]["last"])

    btc2cny["CHBTC"] = CHBTC_btc_cny
    btc2cny["YUNBI"] = YUNBI_btc_cny
    btc2cny["OKCOIN"] = OKCOIN_btc_cny

    eth2cny["CHBTC"] = CHBTC_eth_cny
    eth2cny["YUNBI"] = YUNBI_eth_cny
    #eth2cny["OKCOIN"] = OKCOIN_eth_cny

    eth2btc["BTCE"] = BTCE_eth_btc

    for platform in btc2cny :
        btc_num = money/btc2cny[platform]
        print "在" + platform + "网站，btc 价格为" + str(btc2cny[platform])  + " RMB"
        print "在" + platform + "网站，" + str(money) + " RMB可以兑换" + str(btc_num) + " BTC"
        end_btc_num = btc_num - 0.0001

        for p in eth2btc :
            eth_num = end_btc_num/eth2btc[p]
            print "在" + p + "网站，eth 价格为" + str(eth2btc[p]) + "BTC"
            print "在" + p + "网站，" + str(end_btc_num) + " BTC可以兑换" + str(eth_num) + " ETH"
            end_eth_num = eth_num - 0.01
            
            for q in eth2cny :
                end_cny = eth2cny[q] * end_eth_num
                print "在" + q + "网站，eth 价格为" + str(eth2cny[q]) + " RMB"
                print "盈利为" + str(end_cny - money)

"""
使用人民币在国内交易所购买eth，然后将eth转到国外交易所的账户中
在国外交易所使用eth购买btc，然后将btc转入到国内交易所的账户中
获得的最大利润
"""

def get_max_profit_eth_btc(money) :
    pass    

if __name__ == "__main__" :
    
    get_max_profit_btc_eth(1000)
